package com.contextor.magiccards.web.amf;

import com.contextor.magiccards.web.to.Response;
import com.contextor.magiccards.web.to.battle.BattleListTO;
import com.contextor.magiccards.web.to.battle.BattleTO;
import com.contextor.magiccards.web.to.battle.CombatTO;
import com.contextor.magiccards.web.to.user.PersonageTO;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.stereotype.Service;

/**
 * User: sergey
 * Date: Mar 22, 2011 11:53:46 AM
 */
@Service
@RemotingDestination
public class AmfBattleService extends BaseAmfService {

    public Response<BattleTO> createBattle(String uid) {
        logger.info("createBattle; uid={}", uid);
        try {
            return new Response<BattleTO>(battleHandler.create(uid));
        } catch (Throwable e) {
            return onError(e);
        }
    }

    public Response<BattleListTO> listBattles(String uid) {
        logger.info("listBattles; uid={}", uid);
        try {
            return new Response<BattleListTO>(battleHandler.listBattles(uid));
        } catch (Throwable e) {
            return onError(e);
        }
    }

    public Response<CombatTO> joinBattle(String uid, PersonageTO personageTO, BattleTO battleTO) {
        logger.info("listBattles; uid={}, battleId={}", uid, battleTO.id);
        try {
            return new Response<CombatTO>(battleHandler.joinBattle(uid, personageTO, battleTO));
        } catch (Throwable e) {
            return onError(e);
        }
    }
}
